# 模拟 1000 次随机行走，每步 100 步

import numpy as np

n_simulations = 1000
n_steps = 100

final_positions = []
all_paths = []

for _ in range(n_simulations):
    steps = np.random.choice([1, -1], size=n_steps)
    path = np.cumsum(steps)
    path = np.insert(path, 0, 0)
    all_paths.append(path)
    final_positions.append(path[-1])

final_positions = np.array(final_positions)

print(f"模拟 {n_simulations} 次，100 步后：")
print(f"平均位置: {final_positions.mean():.4f} (理论: 0)")
print(f"位置方差: {final_positions.var():.4f} (理论: 100)")
